home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / NTUMIN10.ARJ / WI_GEN.C < prev   
C/C++ Source or Header  |  1992-03-12  |  3KB  |  91 lines

  1. /****************************************************************************
  2. *
  3. *    Program Name : WI_GEN.C
  4.  *
  5.  *    Written By : Eng-Huat Ong and Kian-Mong Low.
  6. *
  7. *       This program generates wi which is the number of minterms adjacent to
  8. *    mi that are in CPT but not in the given boolean function where mi is
  9. *     a term adjacent to the minterm of interest.
  10. *
  11. *    Returns wi, no. of adjacent terms of mi in e-array but not in a-array
  12.  *
  13.  * --------------------------------------------------------------------------
  14.  *    Copyright (c) 1992. All Rights Reserved. Nanyang Technological
  15.  *    University.
  16.  *
  17.  *    You are free to use, copy and distribute this software and its
  18.  *    documentation providing that:
  19.  *
  20.  *        NO FEE IS CHARGED FOR USE, COPYING OR DISTRIBUTION.
  21.  *
  22.  *        IT IS NOT MODIFIED IN ANY WAY.
  23.  *
  24.  *        THE COPYRIGHT NOTICE APPEAR IN ALL COPIES.
  25.  *
  26.  *    This program is provided "AS IS" without any warranty, expressed or
  27.  *    implied, including but not limited to fitness for any particular
  28.  *    purpose.
  29.  *
  30.  *    If you find NTUMIN fast, easy, and useful, a note or comment would be
  31.  *    appreciated. Please send to:
  32.  *
  33.  *        Boon-Tiong Tan or Othman Bin Ahmad
  34.  *        School of EEE
  35.  *        Nanyang Technological University
  36.  *        Nanyang Avenue
  37.  *        Singapore 2263
  38.  *        Republic of Singapore
  39. *
  40. *****************************************************************************/
  41.  
  42. #include <stdio.h>
  43. #include <stdlib.h>
  44.  
  45. unsigned char   adj_of_mi(mi, e, a)
  46. unsigned char   *mi, *e, *a;
  47.  
  48. {
  49.    unsigned short    ma;
  50.    unsigned long     me, topow();
  51.    unsigned char     j, nspm, n, i, wi, *adjterm;
  52.    char              test;
  53.  
  54.    n = *a;                                   /* no. of variables */
  55.    nspm = *(a+3);                            /* no. of bytes/minterm */
  56.    ma = *(a+2)<<8 | *(a+1);                  /* no. of minterms in a-array */
  57.  
  58.    me = topow(*(e+1));                       /* no. of minterms in e-array */
  59.  
  60.    adjterm = (unsigned char *) malloc(nspm+1);        /* temporary storage */
  61.    if (adjterm == 0)
  62.       {
  63.      printf("Out of memory -- WI_GEN, *adjterm\n");
  64.      printf("Program terminated - 1\n");
  65.      exit(0);
  66.       }
  67.  
  68.    wi = 0;                             /* reset to zero */
  69.  
  70.    for (i=0; i<n; i++)                 /* generate possible adj terms to mi */
  71.       {
  72.      for (j=0; j<nspm; j++)        /* byte operation for nspm>1 */
  73.         {
  74.            if ((i/8) == j)
  75.           *(adjterm + j) = *(mi + j) ^ (1<<(i%8));   /* XOR */
  76.            else
  77.           *(adjterm + j) = *(mi + j);
  78.         }
  79.  
  80.      test = exist(adjterm, e, me);       /* present in e-array ? */
  81.      if (test == 0)                      /* YES */
  82.         {
  83.            test = exist(adjterm, a, ma);       /* present in a-array ? */
  84.            if (test == -1)                     /* NO */
  85.           wi++;                            /* increment wi */
  86.         }
  87.       }
  88.    free(adjterm);                            /* free pointer */
  89.  
  90.    return(wi);                     /* return wi */
  91. }